package com.fashion.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fashion.model.brand.Brand;

/**
 * User: juventus
 * Date: 11-5-3
 * Time: 下午4:23
 */
@Entity
@Table(name = "NEWSCOLUMN")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class NewsColumn implements Serializable {
    private String id;
    private String parentId;
    private String name;
    private Date createDateTime;
    private String url;
    private String title;
    private String keywords;
    private String description;
    private List<Brand> brandsByIndustry;
    private List<Brand> brandsByDistrict; 

    @Transient
	private List<NewsColumn> children = new ArrayList<NewsColumn>();

    private List<NewsColumn> childrenColumns = new ArrayList<NewsColumn>();

    public void addChildColumn(NewsColumn column) {
        childrenColumns.add(column);
    }

    public NewsColumn() {
    }

    public NewsColumn(String id, String parentId, String name, String url) {
        this.id = id;
        this.parentId = parentId;
        this.name = name;
        this.url = url;
    }

    public NewsColumn(String id, String parentId, String name, Date createDateTime,String url,String title) {
        this.id = id;
        this.parentId = parentId;
        this.name = name;
        this.createDateTime = createDateTime;
        this.url = url;
        this.title = title;
    }

    @Id
    @Column(name = "Id", unique = true, nullable = false, length = 64)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "name", length = 256)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "createDateTime")
    public Date getCreateDateTime() {
        return createDateTime;
    }

    public void setCreateDateTime(Date createDateTime) {
        this.createDateTime = createDateTime;
    }

    @Column(name = "parentId", length = 64)
    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    @JSON(name = "children")
    @Transient
    public List<NewsColumn> getChildrenColumns() {
        return childrenColumns;
    }

    public void setChildrenColumns(List<NewsColumn> childrenColumns) {
        this.childrenColumns = childrenColumns;
    }
    
    @Transient
	public List<NewsColumn> getChildren() {
		return children;
	}

	public void setChildren(List<NewsColumn> children) {
		this.children = children;
	}

    @Column
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Column
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column
    public String getKeywords() {
        return keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    @Column
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @ManyToMany(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST,CascadeType.MERGE},  
            mappedBy="industries",  
            targetEntity=Brand.class  
        ) 
	public List<Brand> getBrandsByIndustry() {
		return brandsByIndustry;
	}

    public void setBrandsByIndustry(List<Brand> brandsByIndustry) {
		this.brandsByIndustry = brandsByIndustry;
	}

    @OneToMany( 
    		fetch=FetchType.LAZY,
            mappedBy="district",  
            targetEntity=Brand.class  
        ) 
	public List<Brand> getBrandsByDistrict() {
		return brandsByDistrict;
	}

	public void setBrandsByDistrict(List<Brand> brandsByDistrict) {
		this.brandsByDistrict = brandsByDistrict;
	}

	
    
    
}
